
%%% Weighting the Evidence: A Rank-Dependent Model of Outdoor Recreation, June 2024
%%% This function creates T catch-per-trip distributions from data 

function [catchPerTrip]=CatchTripDistribution(N,M,T,data)

for n=1:size(data,1)  
    if data(n,3)==0
        r(n,:)=data(n,2)*ones(1,T-1);
    else
        pd1=makedist('Normal','mu',data(n,2),'sigma',data(n,3));
        pt=truncate(pd1,0,inf);
        r(n,:)=random(pt,1,T-1);
    end
end

D=horzcat(round(data(:,1)),data(:,2),round(r));
D(1:end,1)=D(1:end,1)+1;
  
for t=1:T
    d=accumarray(D(:,1),D(:,t+1));  
    d=d./sum(d);
    catchPerTrip(:,:,t)=gendist(d(:,1)',M,N)-1;
end

end

